﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VFTray
{
	public partial class WndConfigServer : Form
	{
		public WndConfigServer()
		{
			InitializeComponent();
			TopLevel = false;
			VisibleChanged += (s, e) =>
			  {
				  ipPort1.IP = GlobalParams.CD.ComServer.IP;
				  ipPort1.Port = GlobalParams.CD.ComServer.Port;
			  };
		}

		internal void OnUiTimer()
		{
		}

		private void buttonSet_Click(object sender, EventArgs e)
		{
			if(MessageBox.Show(this,"确定要修改IP地址吗？","请确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question)!= DialogResult.Yes)
			{
				return;
			}

			string ip = GlobalParams.CD.ComServer.IP;
			int port = GlobalParams.CD.ComServer.Port;
			try
			{
				ip = ipPort1.IP;
				port = ipPort1.Port;
				GlobalParams.CDF.Save();
			}
			catch(Exception ex)
			{
				MessageBox.Show(this, "地址错误" + Environment.NewLine + ex.Message, "ERROR");
				return;
			}

			GlobalParams.CD.ComServer.IP = ipPort1.IP;
			GlobalParams.CD.ComServer.Port = ipPort1.Port;
			GlobalParams.CS.Close();
			GlobalParams.CS.Init();
		}
	}
}
